package com.exrobot.module.rbt.enums;

import com.exrobot.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum RbtTaskStatusEnum implements ArrayValuable<Integer> {
    // ========== 机器人任务状态 ==========
    UNEXEC(0,"待执行"),
    DISPATCH(1,"调度中"),
    START(10, "开始"),
    END(20, "结束"),
    ;

    /**
     * 类型值
     */
    private final Integer val;
    /**
     * 类型名
     */
    private final String name;

    public static final Integer[] ARRAYS = Arrays.stream(values()).map(RbtTaskStatusEnum::getVal).toArray(Integer[]::new);

    public static RbtTaskStatusEnum validateVal(Integer val) {
        for (RbtTaskStatusEnum typeEnum : RbtTaskStatusEnum.values()) {
            if (typeEnum.getVal().equals(val)) {
                return typeEnum;
            }
        }
        throw new IllegalArgumentException("非法类型： " + val);
    }

    public static String getName(Integer val) {
        for (RbtTaskStatusEnum typeEnum : RbtTaskStatusEnum.values()) {
            if (typeEnum.getVal().equals(val)) {
                return typeEnum.name;
            }
        }
        return "未知";
    }

    @Override
    public Integer[] array() {
        return ARRAYS;
    }
}
